package com.mybatis.framework;

import javax.sql.DataSource;

import org.mybatis.spring.SqlSessionFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DriverManagerDataSource;

/**
 * com.mybatis.framework
 *
 * @author humdeef
 * @since 2019-07-14
 */
@Configuration
public class Config {

  @Bean
  public DataSource dataSource() {
    DriverManagerDataSource driver = new DriverManagerDataSource();
    driver.setDriverClassName("com.mysql.jdbc.Driver");
    driver.setPassword("123456");
    driver.setUsername("root");
    driver.setUrl("jdbc:mysql://localhost:3306/test");
    return driver;
  }

  @Bean
  public SqlSessionFactoryBean sqlSessionFactoryBean(DataSource dataSource) {
    SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean();
    sqlSessionFactoryBean.setDataSource(dataSource);
    return sqlSessionFactoryBean;
  }
}
